<script setup lang="ts">
import { UserAPI } from "@/api/UserAPI";
import { useUserStore } from "@/stores/userStore";
import ajaxsuccess from "@/utils/ajaxsuccess";
import type { MessageBoard } from "@/types/User";
//获取用户名store对象
const userStore = useUserStore();
const { userinfo } = storeToRefs(userStore);
//反馈内容
const textex = ref();
//邮箱
const emails = ref();
//创建反馈对象
const Message = ref<MessageBoard>({
  email: "",
  content: "",
});
async function Published() {
  Message.value.content = textex.value.value;
  Message.value.email = emails.value.value;

  const response = await UserAPI.Leave_message(Message.value);
  const iftrue = ajaxsuccess(response);
  if (!iftrue) {
    textex.value.value = "";
  }
}
</script>
<template>
  <main>
    <div id="wrap">
      <div id="form_wrap">
        <form>
          <h2>’留 言</h2>

          <label for="email" style="font-size: 12px; color: #000"
            >方享你的问题，我将尽力解决~</label
          >

          <textarea name="message" ref="textex" id="message"></textarea>

          <div class="input">
            <input
              type="text"
              name="name"
              :value="userinfo.result.username"
              id="name"
            />
            <input
              type="text"
              name="email"
              ref="emails"
              placeholder="请输入你邮箱"
              :value="userinfo.result.email"
              id="email"
            />
          </div>

          <button @click.prevent="Published">发表</button>
        </form>
      </div>
    </div>

    <div
      style="position: fixed; height: 90px; width: 100%; left: 0; bottom: 10px"
    >
      <div class="footer-banner" style="width: 728px; margin: 0px auto"></div>
    </div>
  </main>
</template>
<style scoped lang="scss">
p {
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
}
main {
  background: url(https://www.adicw.cn/assets/contact-bg.d29f59aa.jpg);
}
body {
  color: #7c7873;
  font-family: "YanoneKaffeesatzRegular";
  background-color: #d7d7d7;
}
p {
  text-shadow: 0 1px 0 #fff;
  font-size: 24px;
}
#wrap {
  width: 530px;
  margin: 20px auto 0;
  height: 100%;
}
h1 {
  margin-bottom: 20px;
  text-align: center;
  font-size: 48px;
  text-shadow: 0 1px 0 #ede8d9;
}
#form_wrap {
  overflow: hidden;
  padding-top: 60px;
  height: 446px;
  position: relative;
  top: 0px;
  -webkit-transition: all 1s ease-in-out 0.3s;
  -moz-transition: all 1s ease-in-out 0.3s;
  -o-transition: all 1s ease-in-out 0.3s;
  transition: all 1s ease-in-out 0.3s;
  &:before {
    content: "";
    position: absolute;
    bottom: 128px;
    left: 0px;
    background: url("./images/before.png");
    width: 530px;
    height: 316px;
  }
  &:after {
    content: "";
    position: absolute;
    bottom: 0px;
    left: 0;
    background: url("./images/after.png");
    width: 530px;
    height: 260px;
  }
  &:hover {
    height: 656px;
    top: -200px;
    form {
      height: 390px;
    }
    input[type="submit"],
    button {
      z-index: 1;
      opacity: 1;
      -webkit-transition: opacity 0.5s ease-in-out 1.3s;
      -moz-transition: opacity 0.5s ease-in-out 1.3s;
      -o-transition: opacity 0.5s ease-in-out 1.3s;
      transition: opacity 0.5s ease-in-out 1.3s;
    }
    button {
      &:hover {
        color: #435c70;
      }
    }
  }
  input[type="submit"],
  button {
    position: relative;
    font-family: "YanoneKaffeesatzRegular";
    margin-top: 10px;
    font-size: 24px;
    color: #7c7873;
    text-shadow: 0 1px 0 #fff;
    width: 100%;
    text-align: center;
    opacity: 0;
    background: none;
    cursor: pointer;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    border-radius: 3px;
    -webkit-transition: opacity 0.6s ease-in-out 0s;
    -moz-transition: opacity 0.6s ease-in-out 0s;
    -o-transition: opacity 0.6s ease-in-out 0s;
    transition: opacity 0.6s ease-in-out 0s;
  }
}
#form_wrap.hide:after,
#form_wrap.hide:before {
  display: none;
}
form {
  background: white;
  position: relative;
  top: 200px;
  overflow: hidden;
  height: 200px;
  width: 400px;
  margin: 0px auto;
  padding: 20px;
  border: 1px solid #fff;
  border-radius: 3px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  box-shadow: 0px 0px 3px #9d9d9d, inset 0px 0px 27px #fff;
  -moz-box-shadow: 0px 0px 3px #9d9d9d, inset 0px 0px 14px #fff;
  -webkit-box-shadow: 0px 0px 3px #9d9d9d, inset 0px 0px 27px #fff;
  -webkit-transition: all 1s ease-in-out 0.3s;
  -moz-transition: all 1s ease-in-out 0.3s;
  -o-transition: all 1s ease-in-out 0.3s;
  transition: all 1s ease-in-out 0.3s;
  .input {
    display: flex;
    justify-content: space-between;
    input,
    button {
      width: 165px;
    }
  }
  button {
    position: relative;
    left: 50%;
    transform: translate(-50%);
    margin-top: 16px;
    width: 118px;
    height: 32px;
    background-color: rgb(102, 102, 102);
    color: rgb(255, 255, 255);
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }
}
label {
  margin: 11px 20px 0 0;
  font-size: 16px;
  color: #b3aba1;
  text-transform: uppercase;
  text-shadow: 0px 1px 0px #fff;
}
input[type="text"],
textarea {
  font: 14px normal normal uppercase helvetica, arial, serif;
  color: #7c7873;
  background: none;
  width: 380px;
  height: 36px;
  padding: 0px 10px;
  margin: 0 0 10px 0;
  border: 1px solid #edeff3;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
  border-radius: 5px;
  -moz-box-shadow: inset 0px 0px 1px #726959;
  -webkit-box-shadow: inset 0px 0px 1px #b3a895;
  box-shadow: inset 0px 0px 1px #b3a895;
}
textarea {
  height: 80px;
  padding-top: 14px;
}
textarea:focus,
input[type="text"]:focus {
  background: rgba(255, 255, 255, 0.35);
}
.top-banner {
  background-color: #555;
}
</style>
